package it.koutifaris.travianmap.tile.bounds;

import it.koutifaris.travianmap.tile.TileBounds;
import it.koutifaris.travianmap.utils.InBoundsUtil;

public class DefaultTileBounds implements TileBounds {

	private final int x;
	private final int y;
	private final int width;
	private final int height;

	DefaultTileBounds(int x, int y, int width, int height) {
		this.x = x;
		this.y = y;
		this.width = width;
		this.height = height;
	}

	public static TileBoundsBuilder builder() {
		return new TileBoundsBuilderImpl();
	}

	@Override
	public int x() {
		return x;
	}

	@Override
	public int y() {
		return y;
	}

	@Override
	public int width() {
		return width;
	}

	@Override
	public int height() {
		return height;
	}

	@Override
	public boolean containsPoint(int x, int y) {
		return InBoundsUtil.isInBounds(this, x, y);
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + height;
		result = prime * result + width;
		result = prime * result + x;
		result = prime * result + y;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (!(obj instanceof DefaultTileBounds))
			return false;
		DefaultTileBounds other = (DefaultTileBounds) obj;
		if (height != other.height)
			return false;
		if (width != other.width)
			return false;
		if (x != other.x)
			return false;
		if (y != other.y)
			return false;
		return true;
	}

}
